<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            margin: 100px auto;
        }

        input {
            color: #999;
            font-size: 12px;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="text" name="" id="" value="用户名" class="ipt">
    </div>
    <script>
        var ipt = document.querySelector('.ipt');
        ipt.onfocus = function () {
            if (this.value === '用户名') {
                this.value = '';
            }
            this.style.color = '#333'
        }
        ipt.onblur = function () {
            if (this.value === '') {
                this.value = '用户名';
            }
            this.style.color = '#999'
        }
    </script>
</body>

</html>



<!-- <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: relative;
            width: 200px;
            height: 30px;
            margin: 100px auto;
            background-color: pink;
        }

        .box1 {
            position: absolute;
            top: 0;
            right: 0;
            width: 20px;
            height: 20px;
            text-align: center;
            line-height: 20px;
            font-size: 12px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="box1">×</div>
    </div>
    <script>
        var box = document.querySelector('.box');
        var box1 = document.querySelector('.box1');
        box1.onclick = function () {
            box.style.display = 'none';
        }
    </script>
</body>

</html> -->



<!-- <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 50px;
            height: 50px;
            background-color: pink;
        }

        .box1 {
            display: none;
            width: 50px;
            height: 300px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <div class="box1"></div>
    <script>
        var box = document.querySelector('.box');
        var box1 = document.querySelector('.box1');
        box.onmouseover = function () {
            box1.style.display = 'block';
        }
        box.onmouseout = function () {
            box1.style.display = 'none';
        }
    </script>
</body>

</html> -->


<!-- <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .boby {
            background-color: #fff;
        }
    </style>
</head>

<body class="boby">
    <button class="btn">开关</button>
    <script>
        var btn = document.querySelector('.btn');
        var boby = document.querySelector('.boby');
        var flag = 0;
        btn.onclick = function () {
            if (flag == 0) {
                boby.style.backgroundColor = '#000';
                flag = 1;
            } else {
                boby.style.backgroundColor = '#fff';
                flag = 0;
            }
        }
    </script>
</body>

</html> -->